package com.example.netlib.loading;

import android.app.Activity;
import android.util.Log;

import com.szlanyou.thirdsdk.retrofit.client.LoadingActionManager;
import com.szlanyou.thirdsdk.retrofit.loading.NetLoadingStateAction;
import com.szlanyou.thirdsdk.retrofit.util.MyLogUtil;

/**
 * @author 陈章
 * create at 2020/11/19 16:23
 * desc:Dialog形式的进度框
 */
public class DialogLoadingAction extends NetLoadingStateAction {
    private static final String TAG = "DialogLoadingAction";
    private LoadingDialog loadingDialog;
    public DialogLoadingAction(Activity activity) {
        super(activity);
        loadingDialog = new LoadingDialog(activity);
    }

    @Override
    public boolean isShowing() {
        if(loadingDialog == null){
            return false;
        }
        return loadingDialog.isShowing();
    }

    @Override
    public void showLoading(String loadingTip) {
        if(loadingDialog == null){
            return;
        }
        if(null == loadingTip){
            loadingDialog.showLoading(loadingTip);
        }else{
            loadingDialog.showLoading();
        }
        Log.d(TAG,"showLoading on activity " + getActivity());
    }

    @Override
    public void showLoading() {
        if(loadingDialog == null){
            return;
        }
        loadingDialog.showLoading();
        Log.d(TAG,"showLoading on activity " + getActivity());
    }

    @Override
    public void hideLoading() {
        if(loadingDialog == null){
            return;
        }
        loadingDialog.hideLoading();
        Log.d(TAG,"hideLoading on activity " + getActivity());
    }

    @Override
    public void showFailure(Throwable e) {

    }

    @Override
    public void showFailure(Throwable e, String failureTip) {

    }

    @Override
    public void releaseLoading() {
        loadingDialog = null;
        Log.d(TAG,"releaseLoading on activity " + getActivity());
    }

}
